//
//  ContactManager.m
//  04_集合(字典)
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ContactManager.h"

@implementation ContactManager
- (instancetype)initWithDictionary:(NSMutableDictionary *)dictionary {
    self = [super init];
    if (self) {
        _contactDic = dictionary;
    }
    return self;
}
- (void)addContact:(Contact *)contact {
    if (contact.name.length > 0 && contact.phoneNumber.length > 0) {
        NSMutableArray *contactArr = [_contactDic objectForKey:contact.groupName];
        if (contactArr == nil) {
            contactArr = [NSMutableArray arrayWithObject:contact];
            [_contactDic setObject:contactArr forKey:contact.groupName];
        } else {
            [contactArr addObject:contact];
        }
        NSLog(@"添加联系人%@成功", contact.name);
    } else {
        NSLog(@"添加联系人%@失败", contact.name);
    }
}

- (void)removeGroupWithGroupName:(NSString *)groupName {
    [_contactDic removeObjectForKey:groupName];
}

@end
